package com.wg.msshopsp.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wg.msshopsp.entity.Collect;
import org.apache.ibatis.annotations.*;

@Mapper
public interface CollectMapper extends BaseMapper<Collect> {
    @Select("select count(*) from collection where shop_id=#{shopId}")
    int countFanByShopId(Integer shopId);

    // 查询用户是否收藏该店铺（返回 1=已收藏，0=未收藏）
    @Select("select count(*) from collection where user_id=#{userId} and shop_id=#{shopId}")
    int isCollected(@Param("userId") Integer userId, @Param("shopId") Integer shopId);

    // 按用户+店铺删除收藏（支持取消收藏）
    @Delete("delete from collection where user_id=#{userId} and shop_id=#{shopId}")
    int deleteByUserAndShop(@Param("userId") Integer userId, @Param("shopId") Integer shopId);

    // 按用户+店铺添加收藏
    @Insert("insert into collection (user_id, shop_id) values (#{userId}, #{shopId})")
    int insert(@Param("userId") Integer userId, @Param("shopId") Integer shopId);
}
